﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
using Infragistics.Win;
using Infragistics.Win.UltraWinGrid;
using Infragistics.Win.UltraWinCalcManager;
using Infragistics.Win.CalcEngine;
using System.Collections;
using System.Text.RegularExpressions;

namespace BYManageInfoSystem
{
    public partial class Frm_FeeHKCWTruePayTab : DockContent
    {
        private DGBY.BLL.DG_FeeLockTab m_bllDG_FeeLockTab = new DGBY.BLL.DG_FeeLockTab();
        private DGBY.BLL.DG_FeeTruePayLockTab m_bllDG_FeeTruePayLockTab = new DGBY.BLL.DG_FeeTruePayLockTab();
        private DGBY.BLL.PaidanRegisterTab m_bllPaidanRegisterTab = new DGBY.BLL.PaidanRegisterTab();
        private bool m_bClearing = false;
        private DGBY.BLL.FeeHKCWTruePayTab m_bllFeeHKCWTruePayTab = new DGBY.BLL.FeeHKCWTruePayTab();
        private bool m_bInsertFlag = false;
        private int m_nFacID = 0;
        private int m_nDelIndex = -1;
        private DGBY.Model.FeeHKCWTruePayTab m_modelFeeHKCWTruePayTab = new DGBY.Model.FeeHKCWTruePayTab();
        private DGBY.BLL.HxdNoTab m_bllHxdNoTab = new DGBY.BLL.HxdNoTab();
        Hashtable m_SQLStringList = new Hashtable();
        ArrayList m_arrayList = new ArrayList();
        private DGBY.BLL.SJPackingTab m_bllSJPackingTab = new DGBY.BLL.SJPackingTab();
        private DGBY.BLL.BiZhiTab m_bllBiZhiTab = new DGBY.BLL.BiZhiTab();
        private DGBY.BLL.FactoryDataTab m_bllFactoryDataTab = new DGBY.BLL.FactoryDataTab();
        private InsertType m_InsertType = new InsertType();
        private DGBY.BLL.T_ACL_User m_bllT_ACL_User = new DGBY.BLL.T_ACL_User();
        public Frm_FeeHKCWTruePayTab()
        {
            InitializeComponent();
        }

        private void ShowAllRecordInDataGridView()
        {
            string strTemp = this.comboBoxShowWay.Text;
            if (strTemp == "全部记录")
                ShowAllRecord("");
            else
            {
                DateTime dtNow = System.DateTime.Now.Date.AddDays(-180);
                ShowAllRecord("case when year(HxdNoTab.SBDate) = 1900 then getdate() else HxdNoTab.SBDate end >= '" + dtNow + "' or FeeHKCWTruePayTab.PaidanRegisterTabid = -1");
            }
        }

        private void ShowAllRecord(string strWhere)
        {
            DataSet ds = m_bllFeeHKCWTruePayTab.GetList(strWhere);
            ultraGrid1.DataSource = null;



            DataSet dsTemp = m_bllBiZhiTab.GetList("");

            this.ultraDropDownBiZhi.DataSource = dsTemp.Tables[0];
            this.ultraDropDownBiZhi.DisplayMember = "币制名称";
            this.ultraDropDownBiZhi.ValueMember = "BiZhiTabID";
            this.ultraDropDownBiZhi.DisplayLayout.Bands[0].Columns[0].Hidden = true;
            for (int i = 0; i < this.ultraDropDownBiZhi.DisplayLayout.Bands[0].Columns.Count; i++)
                this.ultraDropDownBiZhi.DisplayLayout.Bands[0].Columns[i].Hidden = true;
            this.ultraDropDownBiZhi.DisplayLayout.Bands[0].Columns["币制名称"].Hidden = false;

            dsTemp = m_bllFactoryDataTab.GetList("");

            this.ultraDropDownFac.DataSource = dsTemp.Tables[0];
            this.ultraDropDownFac.DisplayMember = "工厂简称";
            this.ultraDropDownFac.ValueMember = "FactoryDataTabID";
            this.ultraDropDownFac.DisplayLayout.Bands[0].Columns[0].Hidden = true;
            for (int i = 0; i < this.ultraDropDownFac.DisplayLayout.Bands[0].Columns.Count; i++)
                this.ultraDropDownFac.DisplayLayout.Bands[0].Columns[i].Hidden = true;
            this.ultraDropDownFac.DisplayLayout.Bands[0].Columns["工厂简称"].Hidden = false;


            dsTemp = m_bllT_ACL_User.GetList("");

            this.ultraDropDownZhiDanPerson.DataSource = dsTemp.Tables[0];
            this.ultraDropDownZhiDanPerson.DisplayMember = "用户名称";
            this.ultraDropDownZhiDanPerson.ValueMember = "UserPasswordTabID";
            this.ultraDropDownZhiDanPerson.DisplayLayout.Bands[0].Columns[0].Hidden = true;
            for (int i = 0; i < this.ultraDropDownZhiDanPerson.DisplayLayout.Bands[0].Columns.Count; i++)
                this.ultraDropDownZhiDanPerson.DisplayLayout.Bands[0].Columns[i].Hidden = true;
            this.ultraDropDownZhiDanPerson.DisplayLayout.Bands[0].Columns["用户名称"].Hidden = false;

            ultraGrid1.DataSource = ds.Tables[0];


            ultraGrid1.DisplayLayout.Bands[0].Columns[0].Hidden = true;
            ultraGrid1.DisplayLayout.Bands[0].Columns[1].Hidden = true;
            ultraGrid1.DisplayLayout.Bands[0].Columns[2].Hidden = true;
            //ultraGrid1.DisplayLayout.Bands[0].Columns["实付费用计提年月"].Hidden = true;

            this.ultraGrid1.DisplayLayout.Bands[0].Columns["币种"].ValueList = this.ultraDropDownBiZhi;
            this.ultraGrid1.DisplayLayout.Bands[0].Columns["工厂简称"].ValueList = this.ultraDropDownFac;
            this.ultraGrid1.DisplayLayout.Bands[0].Columns["制单人员"].ValueList = this.ultraDropDownZhiDanPerson;

            ultraComboEditor1.DataSource = ds.Tables[0];
            ultraComboEditor1.DisplayMember = "收款人";
            ultraComboEditor1.ValueMember = "收款人";
        }
        private void Frm_FeeHKCWTruePayTab_Load(object sender, EventArgs e)
        {
            InitComBox();

            //SyncSBMonth();
            ClassUltraGridCommonSet.InitUltraWinGridSetting(this.ultraGrid1);
        }

        private void InitComBox()
        {
            this.comboBoxShowWay.Items.AddRange(new object[] { "最近半年记录", "全部记录" });
            this.comboBoxShowWay.SelectedIndex = 0;
        }

        private void SyncSBMonth()
        {
            DataSet dsTemp = m_bllHxdNoTab.ShowZhDjbRec("year(HxdNoTab.SBDate) > 1900");
            DataSet ds = m_bllFeeHKCWTruePayTab.GetList("ShouldPayMonth = 0 or TruePayMonth = 0");
            for (int j = 0; j < ds.Tables[0].Rows.Count; j++)
            {
                string strContractNo = ds.Tables[0].Rows[j]["合同编号"].ToString();
                int nFeeHKCWTruePayTabID = (int)ds.Tables[0].Rows[j]["FeeHKCWTruePayTabID"];
                DGBY.Model.FeeHKCWTruePayTab modelFeeHKCWTruePayTabOld
               = m_bllFeeHKCWTruePayTab.GetModel(nFeeHKCWTruePayTabID);

                DataRow[] Rows = dsTemp.Tables[0].Select("合同编号 = '" + strContractNo.ToString() + "'");
                if (Rows.Length > 0)
                {
                    DateTime dtSBMonth = (DateTime)Rows[0]["申报日期"];
                    int nSBMonth = dtSBMonth.Month;
                    modelFeeHKCWTruePayTabOld.ShouldPayMonth = nSBMonth;
                    modelFeeHKCWTruePayTabOld.TruePayMonth = nSBMonth;
                    m_bllFeeHKCWTruePayTab.Update(modelFeeHKCWTruePayTabOld);
                }

            }
            //ShowAllRecord("");
            //  MessageBox.Show("同步申报月完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        private void buttonShowAll_Click(object sender, EventArgs e)
        {
            ShowAllRecordInDataGridView();
        }
      
        public static void ultraGrid1_InitializeRowFilter(Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
        {
            //ultraGrid1.DisplayLayout.Override.RowSizing = RowSizing.AutoFree;
            //foreach (UltraGridColumn ugc in ultraGrid1.DisplayLayout.Bands[0].Columns)
            //    ugc.PerformAutoResize();
            // FILTER ROW FUNCTIONALITY RELATED ULTRAGRID SETTINGS
            //e.Layout.Override.RowFilterAction = RowFilterAction.DisableFilteredOutRows;
            // ----------------------------------------------------------------------------------
            // Enable the the filter row user interface by setting the FilterUIType to FilterRow.
            e.Layout.Override.FilterUIType = FilterUIType.FilterRow;
            //e.Layout.Override.RowFilterMode = RowFilterMode.AllRowsInBand;
            // FilterEvaluationTrigger specifies when UltraGrid applies the filter criteria typed 
            // into a filter row. Default is OnCellValueChange which will cause the UltraGrid to
            // re-filter the data as soon as the user modifies the value of a filter cell.
            e.Layout.Override.FilterEvaluationTrigger = FilterEvaluationTrigger.OnCellValueChange;
            //e.Layout.Override.RowFilterMode = RowFilterMode.AllRowsInBand;
            // By default the UltraGrid selects the type of the filter operand editor based on
            // the column's DataType. For DateTime and boolean columns it uses the column's editors.
            // For other column types it uses the Combo. You can explicitly specify the operand
            // editor style by setting the FilterOperandStyle on the override or the individual
            // columns.

            e.Layout.Override.FilterOperandStyle = FilterOperandStyle.DropDownList;

            // By default UltraGrid displays user interface for selecting the filter operator. 
            // You can set the FilterOperatorLocation to hide this user interface. This
            // property is available on column as well so it can be controlled on a per column
            // basis. Default is WithOperand. This property is exposed off the column as well.
            e.Layout.Override.FilterOperatorLocation = FilterOperatorLocation.WithOperand;

            // By default the UltraGrid uses StartsWith as the filter operator. You use
            // the FilterOperatorDefaultValue property to specify a different filter operator
            // to use. This is the default or the initial filter operator value of the cells
            // in filter row. If filter operator user interface is enabled (FilterOperatorLocation
            // is not set to None) then that ui will be initialized to the value of this
            // property. The user can then change the operator as he/she chooses via the operator
            // drop down.
            e.Layout.Override.FilterOperatorDefaultValue = FilterOperatorDefaultValue.StartsWith;

            // FilterOperatorDropDownItems property can be used to control the options provided
            // to the user for selecting the filter operator. By default UltraGrid bases 
            // what operator options to provide on the column's data type. This property is
            // avaibale on the column as well.
            //e.Layout.Override.FilterOperatorDropDownItems = FilterOperatorDropDownItems.All;

            // By default UltraGrid displays a clear button in each cell of the filter row
            // as well as in the row selector of the filter row. When the user clicks this
            // button the associated filter criteria is cleared. You can use the 
            // FilterClearButtonLocation property to control if and where the filter clear
            // buttons are displayed.
            e.Layout.Override.FilterClearButtonLocation = FilterClearButtonLocation.RowAndCell;

            // Appearance of the filter row can be controlled using the FilterRowAppearance proeprty.
            e.Layout.Override.FilterRowAppearance.BackColor = Color.LightYellow;

            // You can use the FilterRowPrompt to display a prompt in the filter row. By default
            // UltraGrid does not display any prompt in the filter row.
            e.Layout.Override.FilterRowPrompt = "Click here to filter data...";

            // You can use the FilterRowPromptAppearance to change the appearance of the prompt.
            // By default the prompt is transparent and uses the same fore color as the filter row.
            // You can make it non-transparent by setting the appearance' BackColorAlpha property 
            // or by setting the BackColor to a desired value.
            e.Layout.Override.FilterRowPromptAppearance.BackColorAlpha = Alpha.Opaque;

            // By default the prompt is spread across multiple cells if it's bigger than the
            // first cell. You can confine the prompt to a particular cell by setting the
            // SpecialRowPromptField property off the band to the key of a column.
            //e.Layout.Bands[0].SpecialRowPromptField = e.Layout.Bands[0].Columns[0].Key;

            // Display a separator between the filter row other rows. SpecialRowSeparator property 
            // can be used to display separators between various 'special' rows, including for the
            // filter row. This property is a flagged enum property so it can take multiple values.
            e.Layout.Override.SpecialRowSeparator = SpecialRowSeparator.FilterRow;

            // You can control the appearance of the separator using the SpecialRowSeparatorAppearance
            // property.
            e.Layout.Override.SpecialRowSeparatorAppearance.BackColor = Color.FromArgb(233, 242, 199);


        }
        private void InitColumnWidth()
        {
            ultraGrid1.DisplayLayout.Bands[0].Columns["编号是否手动生成"].Width = 30;
            ultraGrid1.DisplayLayout.Bands[0].Columns["实付日期"].Width = 95;
            ultraGrid1.DisplayLayout.Bands[0].Columns["对公费用编号"].Width = 130;
            ultraGrid1.DisplayLayout.Bands[0].Columns["对私费用编号"].Width = 130;
            ultraGrid1.DisplayLayout.Bands[0].Columns["是否直接开票"].Width = 50;
            ultraGrid1.DisplayLayout.Bands[0].Columns["录入日期"].Width = 95;
            ultraGrid1.DisplayLayout.Bands[0].Columns["申报日期"].Width = 95;
            ultraGrid1.DisplayLayout.Bands[0].Columns["申报年月"].Width = 60;
            ultraGrid1.DisplayLayout.Bands[0].Columns["经营单位"].Width = 60;
            ultraGrid1.DisplayLayout.Bands[0].Columns["部门"].Width = 60;
            ultraGrid1.DisplayLayout.Bands[0].Columns["跟单人员"].Width = 60;
            ultraGrid1.DisplayLayout.Bands[0].Columns["工厂简称"].Width = 60;
            ultraGrid1.DisplayLayout.Bands[0].Columns["合同编号"].Width = 75;
            ultraGrid1.DisplayLayout.Bands[0].Columns["币种"].Width = 50;
            ultraGrid1.DisplayLayout.Bands[0].Columns["制单人员"].Width = 60;
            ultraGrid1.DisplayLayout.Bands[0].Columns["实付汇率"].Width = 60;
            ultraGrid1.DisplayLayout.Bands[0].Columns["实付金额"].Width = 60;
            ultraGrid1.DisplayLayout.Bands[0].Columns["实付手续费"].Width = 60;
            ultraGrid1.DisplayLayout.Bands[0].Columns["实付金额折合人民币"].Width = 60;
            ultraGrid1.DisplayLayout.Bands[0].Columns["应收汇率"].Width = 60;
            ultraGrid1.DisplayLayout.Bands[0].Columns["应收快递费"].Width = 60;
            ultraGrid1.DisplayLayout.Bands[0].Columns["应收金额折合人民币"].Width = 60;
            ultraGrid1.DisplayLayout.Bands[0].Columns["经办人"].Width = 60;
            ultraGrid1.DisplayLayout.Bands[0].Columns["收款人"].Width = 60;
            ultraGrid1.DisplayLayout.Bands[0].Columns["应收费用计提年月"].Width = 50;
            ultraGrid1.DisplayLayout.Bands[0].Columns["实付费用计提年月"].Width = 50;
            ultraGrid1.DisplayLayout.Bands[0].Columns["备注"].Width = 100;
        }
        private void ultraGrid1_InitializeLayout(object sender, InitializeLayoutEventArgs e)
        {
            InitColumnWidth();
            SummarySettings averageSummary =
e.Layout.Bands[0].Summaries.Add(
"实付金额折合人民币",
SummaryType.Sum,
e.Layout.Bands[0].Columns["实付金额折合人民币"]);
            averageSummary.SummaryPosition = SummaryPosition.UseSummaryPositionColumn;
            averageSummary.SummaryPositionColumn = averageSummary.SourceColumn;
            averageSummary.DisplayFormat = "{0:.##}";
            averageSummary.Band.Override.SummaryFooterCaptionVisible = DefaultableBoolean.False;
            averageSummary.Band.Override.BorderStyleSummaryFooter = UIElementBorderStyle.None;
            averageSummary.SummaryDisplayArea = SummaryDisplayAreas.TopFixed;

            averageSummary =
e.Layout.Bands[0].Summaries.Add(
"应收金额折合人民币",
SummaryType.Sum,
e.Layout.Bands[0].Columns["应收金额折合人民币"]);
            averageSummary.SummaryPosition = SummaryPosition.UseSummaryPositionColumn;
            averageSummary.SummaryPositionColumn = averageSummary.SourceColumn;
            averageSummary.DisplayFormat = "{0:.##}";
            averageSummary.Band.Override.SummaryFooterCaptionVisible = DefaultableBoolean.False;
            averageSummary.Band.Override.BorderStyleSummaryFooter = UIElementBorderStyle.None;
            averageSummary.SummaryDisplayArea = SummaryDisplayAreas.TopFixed;

            e.Layout.Bands[0].Columns["收款人"].EditorControl = this.ultraComboEditor1;

            if (this.checkBox1.Checked == true)
                ultraGrid1_InitializeRowFilter(e);
            else
                ClassUltraGridCommonSet.ultraGrid1_InitializeRowFilter(e);

            foreach (UltraGridColumn column2 in ultraGrid1.DisplayLayout.Bands[0].Columns)
            {
                string str = column2.Header.Caption;
                if (str == "合同编号" || str == "经营单位"
                    || str == "部门" || str == "实付金额折合人民币" || str == "应收金额折合人民币"
                    || str == "对公费用编号" || str == "对私费用编号" || str == "跟单人员"
                    || str == "录入日期" || str == "商检日期" || str == "经办人" || str == "实付日期")
                {
                    column2.CellAppearance.BackColor = Color.Coral;
                    column2.CellActivation = Activation.ActivateOnly;
                }
            }
        }
        private void ultraGrid1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter && e.Modifiers == Keys.Control)
            {

                if (!m_bInsertFlag)
                {
                    UltraGridRow row = this.ultraGrid1.DisplayLayout.Bands[0].AddNew();
                    //  row.Cells[2] = DateTime.Parse("1900-01-01");
                }
            }
            switch (e.KeyCode)
            {

                case Keys.Up:
                    {
                        UltraGridCell gridCell = this.ultraGrid1.ActiveCell;
                        if (null == gridCell)
                            return;     

                        string strTemp = this.ultraGrid1.ActiveCell.Column.Header.Caption;
                        //if (strTemp == "经营公司" | strTemp == "客户" | strTemp == "币种" | strTemp == "收款方式")
                        //    return;
                        int nColumnIndex = this.ultraGrid1.ActiveCell.Column.Index;
                        int nIndex = ultraGrid1.ActiveRow.Index;
                        if (nIndex > 0)
                            nIndex--;
                        this.ultraGrid1.PerformAction(UltraGridAction.ExitEditMode, false,
                          false);
                        this.ultraGrid1.PerformAction(UltraGridAction.AboveCell, false,
                          false);
                        e.Handled = true;
                        ultraGrid1.Rows[nIndex].Cells[nColumnIndex].IgnoreRowColActivation = true;
                        ultraGrid1.Rows[nIndex].Cells[nColumnIndex].Activation = Activation.AllowEdit;
                        ultraGrid1.Rows[nIndex].Cells[nColumnIndex].Activate();
                        this.ultraGrid1.PerformAction(UltraGridAction.EnterEditMode, false,
                          false);
                        break;
                    }

                case Keys.Down:
                    {
                        UltraGridCell gridCell = this.ultraGrid1.ActiveCell;
                        if (null == gridCell)
                            return;     

                        string strTemp = this.ultraGrid1.ActiveCell.Column.Header.Caption;
                        //if (strTemp == "经营公司" | strTemp == "客户" | strTemp == "币种" | strTemp == "收款方式")
                        //    return;
                        int nColumnIndex = this.ultraGrid1.ActiveCell.Column.Index;
                        int nIndex = ultraGrid1.ActiveRow.Index;
                        if (nIndex < ultraGrid1.Rows.Count - 1)
                            nIndex++;
                        this.ultraGrid1.PerformAction(UltraGridAction.ExitEditMode, false,
                          false);
                        this.ultraGrid1.PerformAction(UltraGridAction.BelowCell, false,
                          false);
                        e.Handled = true;
                        ultraGrid1.Rows[nIndex].Cells[nColumnIndex].IgnoreRowColActivation = true;
                        ultraGrid1.Rows[nIndex].Cells[nColumnIndex].Activation = Activation.AllowEdit;
                        ultraGrid1.Rows[nIndex].Cells[nColumnIndex].Activate();
                        this.ultraGrid1.PerformAction(UltraGridAction.EnterEditMode, false,
                          false);
                        break;
                    }

                case Keys.Right:
                    this.ultraGrid1.PerformAction(UltraGridAction.ExitEditMode, false,
                      false);
                    this.ultraGrid1.PerformAction(UltraGridAction.NextCellByTab, false,
                      false);
                    e.Handled = true;
                    this.ultraGrid1.PerformAction(UltraGridAction.EnterEditMode, false,
                      false);
                    break;
                case Keys.Left:
                    this.ultraGrid1.PerformAction(UltraGridAction.ExitEditMode, false,
                      false);
                    this.ultraGrid1.PerformAction(UltraGridAction.PrevCellByTab, false,
                      false);
                    e.Handled = true;
                    this.ultraGrid1.PerformAction(UltraGridAction.EnterEditMode, false,
                      false);
                    break;
            }
        }

        private void ResetRecord(int nFeeSJTruePayTabID)
        {

            try
            {
                DGBY.Model.FeeHKCWTruePayTab modelFeeHKCWTruePayTab
                    = m_bllFeeHKCWTruePayTab.GetModel(nFeeSJTruePayTabID);


   
                modelFeeHKCWTruePayTab.BiZhiTabID = 1;
                modelFeeHKCWTruePayTab.ToPubBianHao = "";
                modelFeeHKCWTruePayTab.ToPrivateBianHao = "";
                modelFeeHKCWTruePayTab.SBDate = DateTime.Parse("1900-01-01");
                modelFeeHKCWTruePayTab.TruePayDate = null;
                modelFeeHKCWTruePayTab.InputDate = null; 
                modelFeeHKCWTruePayTab.TruePayMonth = 0;
                modelFeeHKCWTruePayTab.ShouldPayMonth = 0;
                //modelFeeHKCWTruePayTab.TruePayMoney = 0;
                modelFeeHKCWTruePayTab.TruePayHuiLv = 0;
                modelFeeHKCWTruePayTab.TruePayMoneyWB = 0;
                modelFeeHKCWTruePayTab.TruePaySXFeeWB = 50;
                modelFeeHKCWTruePayTab.TrueRecvHuiLv = 0;
                modelFeeHKCWTruePayTab.TrueRecvKDFeeRMB = 30;


                //modelFeeHKCWTruePayTab.ToPubFormula = "";
                //modelFeeHKCWTruePayTab.ToPrivateFormula = "";

                modelFeeHKCWTruePayTab.JinBanPerson = "";
                modelFeeHKCWTruePayTab.RecvMonyePerson = "";

                modelFeeHKCWTruePayTab.IsToRecvPayTab = 0;
                modelFeeHKCWTruePayTab.IsToFinCheckMoneyTab = 0;
                modelFeeHKCWTruePayTab.Note = "";
                // modelFeeBGTruePayTab.SjDate = System.DateTime.Now.Date;

                modelFeeHKCWTruePayTab.bitFiledReserv1 = false;
                modelFeeHKCWTruePayTab.bitFiledReserv2 = false;

                modelFeeHKCWTruePayTab.stringFiledReserv1 = "";
                modelFeeHKCWTruePayTab.stringFiledReserv2 = "";
                modelFeeHKCWTruePayTab.stringFiledReserv3 = "";
                modelFeeHKCWTruePayTab.stringFiledReserv4 = "";

                //modelFeeHKCWTruePayTab.intFiledReserv1 = (int)ds.Tables[0].Rows[0]["UserPasswordTabID"]; //制单人员
                modelFeeHKCWTruePayTab.intFiledReserv2 = 0;
                modelFeeHKCWTruePayTab.intFiledReserv3 = 0;
                modelFeeHKCWTruePayTab.intFiledReserv4 = 0;

                DateTime dtNow = System.DateTime.Now.Date;
                modelFeeHKCWTruePayTab.datetimeFiledReserv1 = dtNow;
                modelFeeHKCWTruePayTab.datetimeFiledReserv2 = dtNow;

                modelFeeHKCWTruePayTab.decimalFiledReserv1 = 0;
                modelFeeHKCWTruePayTab.decimalFiledReserv2 = 0;
                modelFeeHKCWTruePayTab.decimalFiledReserv3 = 0;
                modelFeeHKCWTruePayTab.decimalFiledReserv4 = 0;

                m_bllFeeHKCWTruePayTab.Update(modelFeeHKCWTruePayTab);

                DGBY.Model.PaidanRegisterTab modelPaidanRegisterTab = m_bllPaidanRegisterTab.GetModel(modelFeeHKCWTruePayTab.PaidanRegisterTabID);
                if (null == modelPaidanRegisterTab)
                    Frm_Main.Log2DB(this.Text, "清空", modelFeeHKCWTruePayTab.FeeHKCWTruePayTabID.ToString());
                else
                    Frm_Main.Log2DB(this.Text, "清空", ultraGrid1.ActiveRow.Cells["合同编号"].Value.ToString());
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
        }

        private void ResetUltraGridRow(int nRowIndex)
        {

            try
            {

                UltraGridRow CurrentUGR;
                CurrentUGR = ultraGrid1.Rows[nRowIndex];

                CurrentUGR.Cells["对公费用编号"].Value = "";
                CurrentUGR.Cells["对私费用编号"].Value = "";

                CurrentUGR.Cells["实付日期"].Value = DBNull.Value;

                CurrentUGR.Cells["录入日期"].Value = DBNull.Value;

                CurrentUGR.Cells["实付费用计提年月"].Value = 0;
                CurrentUGR.Cells["应收费用计提年月"].Value = 0;
                CurrentUGR.Cells["实付汇率"].Value = 0;
                CurrentUGR.Cells["实付金额"].Value = 0;

                CurrentUGR.Cells["实付手续费"].Value = 0;
                CurrentUGR.Cells["实付金额折合人民币"].Value = 0;
                CurrentUGR.Cells["应收汇率"].Value = 0;
                CurrentUGR.Cells["应收快递费"].Value = 0;
                CurrentUGR.Cells["应收金额折合人民币"].Value = 0;
                

                CurrentUGR.Cells["经办人"].Value = "";
                CurrentUGR.Cells["收款人"].Value = "";
                CurrentUGR.Cells["是否直接开票"].Value = false;
                //CurrentUGR.Cells["是否已提取至应收应付登记表"].Value = m_modelFeeSJTruePayTab.IsToRecvPayTab;
                //CurrentUGR.Cells["是否已提取至财务对帐"].Value = m_modelFeeSJTruePayTab.IsToFinCheckMoneyTab;


                CurrentUGR.Cells["备注"].Value = "";


            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
        }
        private bool ModifyGoodsDetail(int nRowIndex)
        {

            try
            {
                if (m_bClearing)
                {
                    m_bClearing = false;
                    return false;
                }
                UltraGridRow CurrentUGR;
                CurrentUGR = ultraGrid1.Rows[nRowIndex];
                bool bRet = CheckModify(CurrentUGR);
                if (!bRet)
                {
                    MessageBox.Show("费用已锁定，不能修改或删除记录！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return false;
                }
                int nFeeHKCWTruePayTabID = Convert.ToInt32(CurrentUGR.Cells[0].Value.ToString(), 10);
                DGBY.Model.FeeHKCWTruePayTab modelFeeHKCWTruePayTab
                    = m_bllFeeHKCWTruePayTab.GetModel(nFeeHKCWTruePayTabID);


                int nPaidanRegisterTabID = (int)CurrentUGR.Cells["PaidanRegisterTabID"].Value;
                int nFactoryDataTabID = (int)CurrentUGR.Cells["FactoryDataTabID"].Value;

                if (nFactoryDataTabID > 0 && nPaidanRegisterTabID == -1)
                {
                    DataSet ds;
                    string strFac = CurrentUGR.Cells["工厂简称"].Value.ToString();
                    if (ClassInputValid.IsNum(strFac))
                    {
                        modelFeeHKCWTruePayTab.FactoryDataTabID = Convert.ToInt32(CurrentUGR.Cells["工厂简称"].Value.ToString(), 10);
                    }
                    else
                    {
                        ds = m_bllFactoryDataTab.GetList("FactoryNameJX = '" + strFac + "'");
                        if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                        {
                            modelFeeHKCWTruePayTab.FactoryDataTabID = Convert.ToInt32(ds.Tables[0].Rows[0]["FactoryDataTabID"].ToString(), 10);
                        }
                    }


                }

                if (CurrentUGR.Cells["实付日期"].Text != "")
                {
                    DateTime dtTemp = Convert.ToDateTime(CurrentUGR.Cells["实付日期"].Value.ToString());
                    modelFeeHKCWTruePayTab.TruePayDate = dtTemp.Date;
                }

                if (modelFeeHKCWTruePayTab.ToPrivateBianHao == "" && modelFeeHKCWTruePayTab.ToPubBianHao == "")
                    modelFeeHKCWTruePayTab.InputDate = System.DateTime.Now.Date;

                modelFeeHKCWTruePayTab.TruePayMonth = Convert.ToInt32(CurrentUGR.Cells["实付费用计提年月"].Value.ToString(), 10);
                modelFeeHKCWTruePayTab.ShouldPayMonth = Convert.ToInt32(CurrentUGR.Cells["应收费用计提年月"].Value.ToString(), 10);
                modelFeeHKCWTruePayTab.bitFiledReserv1 = (bool)CurrentUGR.Cells["是否直接开票"].Value;
                //       modelFeeHKCWTruePayTab.ShouldRecvNotRecvMoney = Convert.ToDecimal(CurrentUGR.Cells["实付金额"].Value.ToString()); ;

                //modelFeeHKCWTruePayTab.ToPubFormula = CurrentUGR.Cells["对公公式"].Value.ToString();
                //modelFeeHKCWTruePayTab.ToPrivateFormula = CurrentUGR.Cells["对私公式"].Value.ToString();
                //if (CurrentUGR.Cells["对公公式"].Value.ToString() != ""
                //    && CurrentUGR.Cells["对私公式"].Value.ToString() != "")
                //{
                //    MessageBox.Show("对公公式,对私公式不能同时添加！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                //    return false;
                //}

                modelFeeHKCWTruePayTab.JinBanPerson = modelFeeHKCWTruePayTab.JinBanPerson != ""
                    ? CurrentUGR.Cells["经办人"].Value.ToString()
                    : Frm_Main.m_strLoginUser;
                modelFeeHKCWTruePayTab.RecvMonyePerson = CurrentUGR.Cells["收款人"].Value.ToString();
                //modelFeeHKCWTruePayTab.MakeSheetPerson = CurrentUGR.Cells["制单人员"].Value.ToString();

                //modelFeeHKCWTruePayTab.IsToRecvPayTab = Convert.ToInt32(CurrentUGR.Cells["是否已提取至应收应付登记表"].Value.ToString(), 10);
                //modelFeeHKCWTruePayTab.IsToFinCheckMoneyTab = Convert.ToInt32(CurrentUGR.Cells["是否已提取至财务对帐"].Value.ToString(), 10);
                modelFeeHKCWTruePayTab.Note = CurrentUGR.Cells["备注"].Value.ToString();

                string strBiZhi = CurrentUGR.Cells["币种"].Value.ToString();
                if (ClassInputValid.IsNum(strBiZhi))
                {
                    modelFeeHKCWTruePayTab.BiZhiTabID = Convert.ToInt32(CurrentUGR.Cells["币种"].Value.ToString(), 10);
                }
                else
                {
                    DataSet ds = m_bllBiZhiTab.GetList("BiZhiName = '" + strBiZhi + "'");
                    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        modelFeeHKCWTruePayTab.BiZhiTabID = Convert.ToInt32(ds.Tables[0].Rows[0]["BiZhiTabID"].ToString(), 10);
                    }
                }

                int intFiledReserv1 = modelFeeHKCWTruePayTab.intFiledReserv1;
                string strBGH = CurrentUGR.Cells["制单人员"].Value.ToString();
                if (ClassInputValid.IsNum(strBGH))
                {
                    modelFeeHKCWTruePayTab.intFiledReserv1 = Convert.ToInt32(CurrentUGR.Cells["制单人员"].Value.ToString(), 10);
                }
                else
                {

                    DataSet ds = m_bllT_ACL_User.GetList("Name = '" + strBGH + "'");
                    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        modelFeeHKCWTruePayTab.intFiledReserv1 = Convert.ToInt32(ds.Tables[0].Rows[0]["UserPasswordTabID"].ToString(), 10);
                    }
                }
                //modelFeeHKCWTruePayTab.BiZhiTabID = Convert.ToInt32(CurrentUGR.Cells["币种"].Value.ToString(), 10);
                modelFeeHKCWTruePayTab.TruePayMoneyWB = Convert.ToDecimal(CurrentUGR.Cells["实付金额"].Value.ToString());
                if (modelFeeHKCWTruePayTab.TruePayMoneyWB != 0)
                {
                    modelFeeHKCWTruePayTab.TruePayHuiLv = Convert.ToDecimal(CurrentUGR.Cells["实付汇率"].Value.ToString());

                    modelFeeHKCWTruePayTab.TruePaySXFeeWB = Convert.ToDecimal(CurrentUGR.Cells["实付手续费"].Value.ToString());
                    modelFeeHKCWTruePayTab.TrueRecvHuiLv = Convert.ToDecimal(CurrentUGR.Cells["应收汇率"].Value.ToString());
                    modelFeeHKCWTruePayTab.TrueRecvKDFeeRMB = Convert.ToDecimal(CurrentUGR.Cells["应收快递费"].Value.ToString());
                }
                else
                {
                    modelFeeHKCWTruePayTab.TruePayHuiLv = 0;

                    modelFeeHKCWTruePayTab.TruePaySXFeeWB = 0;
                    modelFeeHKCWTruePayTab.TrueRecvHuiLv = 0;
                    modelFeeHKCWTruePayTab.TrueRecvKDFeeRMB = 0;
                }
                //if (modelFeeHKCWTruePayTab.ToPubFormula != "")
                //    modelFeeHKCWTruePayTab.TruePayMoney
                //        = this.ultraCalcManager1.Calculate(modelFeeHKCWTruePayTab.ToPubFormula).ToDecimal();
                //else if (modelFeeHKCWTruePayTab.ToPrivateFormula != "")
                //    modelFeeHKCWTruePayTab.TruePayMoney
                //        = this.ultraCalcManager1.Calculate(modelFeeHKCWTruePayTab.ToPrivateFormula).ToDecimal();
                //else
                //    modelFeeHKCWTruePayTab.TruePayMoney = 0;
               // ,BiZhiTab.BiZhiEngName 币种

                bRet = IsFeeTruePayLocked(CurrentUGR) && CheckFeeTruePayModify(modelFeeHKCWTruePayTab);
                if (bRet)
                {
                    MessageBox.Show("实付费用已锁定，不能修改或删除记录！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return false;
                }
       
                m_bllFeeHKCWTruePayTab.Update(modelFeeHKCWTruePayTab);

                CurrentUGR.Cells["收款人"].Value = modelFeeHKCWTruePayTab.RecvMonyePerson;
                CurrentUGR.Cells["经办人"].Value = modelFeeHKCWTruePayTab.JinBanPerson;
                CurrentUGR.Cells["录入日期"].Value = modelFeeHKCWTruePayTab.InputDate;
                CurrentUGR.Cells["实付金额折合人民币"].Value
                    = modelFeeHKCWTruePayTab.TruePayHuiLv * (modelFeeHKCWTruePayTab.TruePayMoneyWB + modelFeeHKCWTruePayTab.TruePaySXFeeWB);
                CurrentUGR.Cells["应收金额折合人民币"].Value
                    = modelFeeHKCWTruePayTab.TrueRecvHuiLv 
                    * (modelFeeHKCWTruePayTab.TruePayMoneyWB + modelFeeHKCWTruePayTab.TruePaySXFeeWB)
                    + modelFeeHKCWTruePayTab.TrueRecvKDFeeRMB;

                DGBY.Model.PaidanRegisterTab modelPaidanRegisterTab = m_bllPaidanRegisterTab.GetModel(modelFeeHKCWTruePayTab.PaidanRegisterTabID);
                if (null == modelPaidanRegisterTab)
                    Frm_Main.Log2DB(this.Text, "修改", modelFeeHKCWTruePayTab.FeeHKCWTruePayTabID.ToString());
                else
                    Frm_Main.Log2DB(this.Text, "修改", ultraGrid1.ActiveRow.Cells["合同编号"].Value.ToString());
                return true;

            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
        }

        private void ultraGrid1_BeforeRowUpdate(object sender, CancelableRowEventArgs e)
        {
            try
            {
                UltraGridRow CurrentUGR;
                CurrentUGR = ultraGrid1.Rows[e.Row.Index];

                if (m_bInsertFlag)
                {
                    ultraGrid1.Rows[e.Row.Index].Cells[2].Activation = Activation.ActivateOnly;
                    m_bInsertFlag = false;

                }
                else//修改
                {

                    ModifyGoodsDetail(e.Row.Index);

                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
        }

        private bool AddGoodsDetail(int nRowIndex)
        {

            try
            {
                UltraGridRow CurrentUGR;
                CurrentUGR = ultraGrid1.Rows[nRowIndex];

                DGBY.Model.FeeHKCWTruePayTab modelFeeHKCWTruePayTab = new DGBY.Model.FeeHKCWTruePayTab();
                modelFeeHKCWTruePayTab = m_modelFeeHKCWTruePayTab;
                modelFeeHKCWTruePayTab.ToPrivateBianHao = "";
                modelFeeHKCWTruePayTab.ToPubBianHao = "";
                modelFeeHKCWTruePayTab.TruePayDate = null;
                m_bllFeeHKCWTruePayTab.Add(modelFeeHKCWTruePayTab);

                DGBY.Model.PaidanRegisterTab modelPaidanRegisterTab = m_bllPaidanRegisterTab.GetModel(modelFeeHKCWTruePayTab.PaidanRegisterTabID);
                if (modelPaidanRegisterTab != null)
                    Frm_Main.Log2DB(this.Text, "复制增加", modelPaidanRegisterTab.ContractCode);
                else
                    Frm_Main.Log2DB(this.Text, "复制增加", modelFeeHKCWTruePayTab.FeeHKCWTruePayTabID.ToString());
               // ShowAllRecord("");
                ShowAllRecord("FeeHKCWTruePayTab.PaidanRegisterTabID = '" + modelFeeHKCWTruePayTab.PaidanRegisterTabID.ToString() + "'");


                return true;

            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
        }

        private void InitNewAddRowValueCopyContract(int nIndex)
        {

            UltraGridRow CurrentUGR = ultraGrid1.Rows[nIndex];

            CurrentUGR.Cells["合同编号"].Value = m_modelFeeHKCWTruePayTab.PaidanRegisterTabID;
            CurrentUGR.Cells["对公费用编号"].Value = m_modelFeeHKCWTruePayTab.ToPubBianHao;
            CurrentUGR.Cells["对私费用编号"].Value = m_modelFeeHKCWTruePayTab.ToPrivateBianHao;
            if (m_modelFeeHKCWTruePayTab.TruePayDate != null)
                CurrentUGR.Cells["实付日期"].Value = m_modelFeeHKCWTruePayTab.TruePayDate;
            if (m_modelFeeHKCWTruePayTab.InputDate != null)
                CurrentUGR.Cells["录入日期"].Value = m_modelFeeHKCWTruePayTab.InputDate;

            CurrentUGR.Cells["实付费用计提年月"].Value = m_modelFeeHKCWTruePayTab.TruePayMonth;
            CurrentUGR.Cells["应收费用计提年月"].Value = m_modelFeeHKCWTruePayTab.ShouldPayMonth;
            //CurrentUGR.Cells["实付金额"].Value = m_modelFeeHKCWTruePayTab.TruePayMoney;

            //CurrentUGR.Cells["对公公式"].Value = m_modelFeeHKCWTruePayTab.ToPubFormula;
            //CurrentUGR.Cells["对私公式"].Value = m_modelFeeHKCWTruePayTab.ToPrivateFormula;
            CurrentUGR.Cells["经办人"].Value = m_modelFeeHKCWTruePayTab.JinBanPerson;
            CurrentUGR.Cells["收款人"].Value = m_modelFeeHKCWTruePayTab.RecvMonyePerson;

            //CurrentUGR.Cells["是否已提取至应收应付登记表"].Value = m_modelFeeHKCWTruePayTab.IsToRecvPayTab;
            //CurrentUGR.Cells["是否已提取至财务对帐"].Value = m_modelFeeHKCWTruePayTab.IsToFinCheckMoneyTab;


            CurrentUGR.Cells["备注"].Value = m_modelFeeHKCWTruePayTab.Note;
            CurrentUGR.Cells["制单人员"].Value = m_modelFeeHKCWTruePayTab.intFiledReserv1;
            if (m_bInsertFlag)
            {
                ultraGrid1.Rows[nIndex].Cells[2].Activation = Activation.ActivateOnly;
                m_bInsertFlag = false;
                AddGoodsDetail(nIndex);

            }

        }

        private void ultraGrid1_AfterCellActivate(object sender, EventArgs e)
        {
            int iIndex = this.ultraGrid1.ActiveCell.Row.Index;
            if (iIndex < 0)
                return;
            m_nDelIndex = ultraGrid1.ActiveRow.Index;

        }
 
           
        private bool AddGoodsDetailNoContractNo(int nRowIndex)
        {

            try
            {
                UltraGridRow CurrentUGR;
                CurrentUGR = ultraGrid1.Rows[nRowIndex];

                DGBY.Model.FeeHKCWTruePayTab modelFeeHKCWTruePayTab = new DGBY.Model.FeeHKCWTruePayTab();

                modelFeeHKCWTruePayTab.ToPrivateBianHao = "";
                modelFeeHKCWTruePayTab.ToPubBianHao = "";
                modelFeeHKCWTruePayTab.TruePayDate = null;

                //modelFeeHKCWTruePayTab.SjDate = System.DateTime.Now.Date;
                //modelFeeHKCWTruePayTab.HKCWCompany = "";
                //modelFeeHKCWTruePayTab.HKCWCountryTabID = 1;
                modelFeeHKCWTruePayTab.FactoryDataTabID = 1;
                modelFeeHKCWTruePayTab.PaidanRegisterTabID = -1;

                modelFeeHKCWTruePayTab.TruePayDate = null;

                DateTime dtNow = System.DateTime.Now.Date;
                modelFeeHKCWTruePayTab.SBDate = dtNow;
                modelFeeHKCWTruePayTab.InputDate = dtNow;
                modelFeeHKCWTruePayTab.TruePayMonth = 1;
                modelFeeHKCWTruePayTab.ShouldPayMonth = 1;

               // modelFeeHKCWTruePayTab.ToPubFormula = "";
              //  modelFeeHKCWTruePayTab.ToPrivateFormula = "";


                modelFeeHKCWTruePayTab.JinBanPerson = "";
                modelFeeHKCWTruePayTab.RecvMonyePerson = "";
                modelFeeHKCWTruePayTab.MakeSheetPerson = "";



                //modelFeeHKCWTruePayTab.IsToRecvPayTab = Convert.ToInt32(CurrentUGR.Cells["是否已提取至应收应付登记表"].Value.ToString(), 10);
                //modelFeeHKCWTruePayTab.IsToFinCheckMoneyTab = Convert.ToInt32(CurrentUGR.Cells["是否已提取至财务对帐"].Value.ToString(), 10);
                modelFeeHKCWTruePayTab.Note = "";

                modelFeeHKCWTruePayTab.BiZhiTabID = 1;
              
                modelFeeHKCWTruePayTab.TruePayHuiLv = 0;
                 modelFeeHKCWTruePayTab.TruePayMoneyWB = 0;
                 modelFeeHKCWTruePayTab.TruePaySXFeeWB = 0;
                 modelFeeHKCWTruePayTab.TrueRecvHuiLv = 0;
                 modelFeeHKCWTruePayTab.TrueRecvKDFeeRMB = 0;


                 modelFeeHKCWTruePayTab.bitFiledReserv1 = false;
                 modelFeeHKCWTruePayTab.bitFiledReserv2 = false;

                 modelFeeHKCWTruePayTab.stringFiledReserv1 = "";
                 modelFeeHKCWTruePayTab.stringFiledReserv2 = "";
                 modelFeeHKCWTruePayTab.stringFiledReserv3 = "";
                 modelFeeHKCWTruePayTab.stringFiledReserv4 = "";

                 modelFeeHKCWTruePayTab.intFiledReserv1 = 0;
                 modelFeeHKCWTruePayTab.intFiledReserv2 = 0;
                 modelFeeHKCWTruePayTab.intFiledReserv3 = 0;
                 modelFeeHKCWTruePayTab.intFiledReserv4 = 0;
                 modelFeeHKCWTruePayTab.datetimeFiledReserv1 = dtNow;
                 modelFeeHKCWTruePayTab.datetimeFiledReserv2 = dtNow;

                 modelFeeHKCWTruePayTab.decimalFiledReserv1 = 0;
                 modelFeeHKCWTruePayTab.decimalFiledReserv2 = 0;
                 modelFeeHKCWTruePayTab.decimalFiledReserv3 = 0;
                 modelFeeHKCWTruePayTab.decimalFiledReserv4 = 0;

                int nID = m_bllFeeHKCWTruePayTab.Add(modelFeeHKCWTruePayTab);
                Frm_Main.Log2DB(this.Text, "增加无合同号记录", nID.ToString());
                //ShowAllRecord("");
                ShowAllRecord("FeeHKCWTruePayTab.FeeHKCWTruePayTabID = '" + nID.ToString() + "'");

                return true;

            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
        }
        
        private void InitNewAddRowValueNoContract(int nIndex)
        {

            UltraGridRow CurrentUGR = ultraGrid1.Rows[nIndex];

            CurrentUGR.Cells["合同编号"].Value = "";
            CurrentUGR.Cells["对公费用编号"].Value = m_modelFeeHKCWTruePayTab.ToPubBianHao;
            CurrentUGR.Cells["对私费用编号"].Value = m_modelFeeHKCWTruePayTab.ToPrivateBianHao;
            if (m_modelFeeHKCWTruePayTab.TruePayDate != null)
                CurrentUGR.Cells["实付日期"].Value = m_modelFeeHKCWTruePayTab.TruePayDate;
            if (m_modelFeeHKCWTruePayTab.InputDate != null)
                CurrentUGR.Cells["录入日期"].Value = m_modelFeeHKCWTruePayTab.InputDate;

            CurrentUGR.Cells["实付费用计提年月"].Value = m_modelFeeHKCWTruePayTab.TruePayMonth;
            CurrentUGR.Cells["应收费用计提年月"].Value = m_modelFeeHKCWTruePayTab.ShouldPayMonth;
            //CurrentUGR.Cells["应付实付金额"].Value = m_modelFeeHKCWTruePayTab.ShouldRecvNotRecvMoney;

            //CurrentUGR.Cells["对公公式"].Value = m_modelFeeHKCWTruePayTab.ToPubFormula;
            //CurrentUGR.Cells["对私公式"].Value = m_modelFeeHKCWTruePayTab.ToPrivateFormula;
            CurrentUGR.Cells["经办人"].Value = m_modelFeeHKCWTruePayTab.JinBanPerson;
            CurrentUGR.Cells["收款人"].Value = m_modelFeeHKCWTruePayTab.RecvMonyePerson;

            //CurrentUGR.Cells["是否已提取至应收应付登记表"].Value = m_modelFeeHKCWTruePayTab.IsToRecvPayTab;
            //CurrentUGR.Cells["是否已提取至财务对帐"].Value = m_modelFeeHKCWTruePayTab.IsToFinCheckMoneyTab;


            CurrentUGR.Cells["备注"].Value = m_modelFeeHKCWTruePayTab.Note;
            CurrentUGR.Cells["制单人员"].Value = m_modelFeeHKCWTruePayTab.intFiledReserv1;
            if (m_bInsertFlag)
            {
                ultraGrid1.Rows[nIndex].Cells[2].Activation = Activation.ActivateOnly;
                m_bInsertFlag = false;
                AddGoodsDetailNoContractNo(nIndex);

            }

        }
        private void ultraGrid1_AfterRowInsert(object sender, RowEventArgs e)
        {
            ultraGrid1.Rows[e.Row.Index].Cells[1].IgnoreRowColActivation = true;
            ultraGrid1.Rows[e.Row.Index].Cells[1].Activation = Activation.AllowEdit;
            ultraGrid1.Rows[e.Row.Index].Cells[1].Activate();
            ultraGrid1.PerformAction(UltraGridAction.EnterEditMode);
            m_bInsertFlag = true;
            if (m_InsertType == InsertType.Common)
                InitNewAddRowValueCopyContract(e.Row.Index);
            else if (m_InsertType == InsertType.WithoutContractNo)
                InitNewAddRowValueNoContract(e.Row.Index);
        }

        private void ultraGrid1_BeforeRowsDeleted(object sender, BeforeRowsDeletedEventArgs e)
        {
            e.DisplayPromptMsg = false;
            if (!m_bInsertFlag)
            {
                int nSelectFeeHKCWTruePayTabID = Convert.ToInt32(ultraGrid1.ActiveRow.Cells["FeeHKCWTruePayTabID"].Value.ToString(), 10);
                DGBY.Model.FeeHKCWTruePayTab modelFeeHKCWTruePayTabOld
                    = m_bllFeeHKCWTruePayTab.GetModel(nSelectFeeHKCWTruePayTabID);

                if (modelFeeHKCWTruePayTabOld == null)
                {
                    MessageBox.Show("数据库不存在该记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                if (MessageBox.Show("确实要删除该条记录!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
                {
                    try
                    {

                        m_bllFeeHKCWTruePayTab.Delete(nSelectFeeHKCWTruePayTabID);

                        DGBY.Model.PaidanRegisterTab modelPaidanRegisterTab = m_bllPaidanRegisterTab.GetModel(modelFeeHKCWTruePayTabOld.PaidanRegisterTabID);
                        if (null == modelPaidanRegisterTab)
                            Frm_Main.Log2DB(this.Text, "删除", modelFeeHKCWTruePayTabOld.FeeHKCWTruePayTabID.ToString());
                        else
                            Frm_Main.Log2DB(this.Text, "删除", ultraGrid1.ActiveRow.Cells["合同编号"].Value.ToString());

                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        e.Cancel = true;
                    }
                }
                else
                {
                    e.Cancel = true;
                }
            }
            else
            {
                MessageBox.Show("插入未完成，不能删除记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                e.Cancel = true;
            }
        }

        private void 复制增加ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                if (!m_bInsertFlag)
                {
                    UltraGridRow CurrentUGRFrom;
                    CurrentUGRFrom = ultraGrid1.Rows[m_nDelIndex];
                    int nSelectFeeHKCWTruePayTabID = Convert.ToInt32(CurrentUGRFrom.Cells[0].Value.ToString(), 10);
                    m_modelFeeHKCWTruePayTab = m_bllFeeHKCWTruePayTab.GetModel(nSelectFeeHKCWTruePayTabID);
                    m_modelFeeHKCWTruePayTab.InputDate = System.DateTime.Now.Date;
                    // m_bCopyInsertFlag = true;
                    m_InsertType = InsertType.Common;
                    UltraGridRow row = this.ultraGrid1.DisplayLayout.Bands[0].AddNew();

                }
            }
            catch
            {
                MessageBox.Show("没有选择记录，无法复制！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        private bool CheckModify(UltraGridRow CurrentUGR)
        {
            int nYearMonth = Convert.ToInt32(CurrentUGR.Cells["应收费用计提年月"].Value.ToString(), 10);
            DataSet ds = m_bllDG_FeeLockTab.GetList("FeeName = '香港船务' and IsLock = 1 and LockYearMonth = '" + nYearMonth.ToString() + "'");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                return false;
            }
            return true;
        }
        private bool IsFeeTruePayLocked(UltraGridRow CurrentUGR)
        {
            int nYearMonth = Convert.ToInt32(CurrentUGR.Cells["实付费用计提年月"].Value.ToString(), 10);
            DataSet ds = m_bllDG_FeeTruePayLockTab.GetList("FeeName = '香港船务' and IsLock = 1 and LockYearMonth = '" + nYearMonth.ToString() + "'");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                return true;
            }
            return false;
        }
        private bool CheckFeeTruePayModify(DGBY.Model.FeeHKCWTruePayTab modeFeeHKCWTruePayTabl)
        {
            DGBY.Model.FeeHKCWTruePayTab oldModeFeeHKCWTruePayTabl = m_bllFeeHKCWTruePayTab.GetModel(modeFeeHKCWTruePayTabl.FeeHKCWTruePayTabID);
            if (null != oldModeFeeHKCWTruePayTabl)
            {
                //限制修改实付日期、费用编号、是否直接开票、应付实付金额
                if (oldModeFeeHKCWTruePayTabl.TruePayDate != modeFeeHKCWTruePayTabl.TruePayDate
                    || oldModeFeeHKCWTruePayTabl.bitFiledReserv1 != modeFeeHKCWTruePayTabl.bitFiledReserv1
                    || oldModeFeeHKCWTruePayTabl.TruePayMoneyWB != modeFeeHKCWTruePayTabl.TruePayMoneyWB
                    || oldModeFeeHKCWTruePayTabl.ToPubBianHao != modeFeeHKCWTruePayTabl.ToPubBianHao
                    || oldModeFeeHKCWTruePayTabl.ToPrivateBianHao != modeFeeHKCWTruePayTabl.ToPrivateBianHao)
                    return true;
            }

            return false;
        }
        private void 删除本行ToolStripMenuItem_Click(object sender, EventArgs e)
        {

            DialogResult dr = MessageBox.Show("确实要删除该记录么!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
            if (dr == DialogResult.Cancel)
            {
                return;
            }
            int nIndex = m_nDelIndex;
            if (m_nDelIndex >= 0)
            {
                if (ultraGrid1.ActiveRow != null)
                {
                    UltraGridRow CurrentUGR = ultraGrid1.Rows[nIndex];
                    bool bRet = CheckModify(CurrentUGR);
                    if (!bRet)
                    {
                        MessageBox.Show("费用已锁定，不能修改或删除记录！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }

                    bRet = IsFeeTruePayLocked(CurrentUGR);
                    if (bRet)
                    {
                        MessageBox.Show("实付费用已锁定，不能修改或删除记录！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }

                    int nPaidanRegisterTabID = Convert.ToInt32(CurrentUGR.Cells["PaidanRegisterTabID"].Value.ToString(), 10);
                    DataSet ds = m_bllFeeHKCWTruePayTab.GetList("FeeHKCWTruePayTab.PaidanRegisterTabID = '" + nPaidanRegisterTabID.ToString() + "'");
                    if (ds.Tables[0].Rows.Count > 1)
                        ultraGrid1.ActiveRow.Delete(false);
                    else
                    {
                        MessageBox.Show("系统中该合同号只剩下一条记录，为系统自动生成，不能删除!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                }
            }
            else
            {
                MessageBox.Show("请选中要删除的记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        private string MakeHKCWBianHaoWithoutLiuShuiNo(string strDepart, string strComp
        , string strPuborPri, string strDate)
        {
            string strRet = "XC" + ClassUtility.m_dicCn2EngDep[strDepart]
+ ClassUtility.m_dicCn2EngComp[strComp] + ClassUtility.m_dicCn2EngGS[strPuborPri] + strDate;

            // string strRet = "XC" + strDepart + strComp + strPuborPri + strDate;
            return strRet;
        }
        private string MakeHKCWBianHao(string strDepart, string strComp
        , string strPuborPri, string strDate, int nSeqNo)
        {
            string strRet = "XC" + ClassUtility.m_dicCn2EngDep[strDepart]
+ ClassUtility.m_dicCn2EngComp[strComp] + ClassUtility.m_dicCn2EngGS[strPuborPri] + strDate + nSeqNo.ToString().PadLeft(3, '0');

            // string strRet = "DC" + strDepart + strComp + strPuborPri + strDate ;
            return strRet;
        }
        private void buttonBatchModifyDate_Click(object sender, EventArgs e)
        {
            m_SQLStringList.Clear();
            m_arrayList.Clear();
            DateTime dtTruePay = this.dateTimePicker1.Value.Date;
            DataSet dsTemp = m_bllFeeHKCWTruePayTab.GetList("TruePayDate = '" + dtTruePay + @"' and (ToPubBianHao != '' or ToPrivateBianHao != '')");
            int nCount = dsTemp.Tables[0].Rows.Count + 1;
            try
            {
                Infragistics.Win.UltraWinGrid.UltraGridRow[] ugr = ultraGrid1.Rows.GetFilteredInNonGroupByRows();
                DialogResult dr = MessageBox.Show("确实要批量修改以下" + ugr.Length.ToString() + "条记录的实付日期么", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                if (dr == DialogResult.Cancel)
                    return;
                for (int i = 0; i < ugr.Length; i++)
                {
                    int nID = Convert.ToInt32(ugr[i].Cells[0].Value.ToString(), 10);
                    DGBY.Model.FeeHKCWTruePayTab modelFeeHKCWTruePayTabOld
                                        = m_bllFeeHKCWTruePayTab.GetModel(nID);
                    DateTime? dtTruePayOld = modelFeeHKCWTruePayTabOld.TruePayDate;
                    modelFeeHKCWTruePayTabOld.TruePayDate = this.dateTimePicker1.Value.Date;

                    UltraGridRow CurrentUGR = ultraGrid1.Rows[ugr[i].Index];
                    if (dtTruePayOld == null && (Decimal)CurrentUGR.Cells["实付金额"].Value > 0)
                    {
                        string strBianHao = MakeHKCWBianHao(ugr[i].Cells["部门"].Value.ToString()
                       , ugr[i].Cells["经营单位"].Value.ToString()
                       , "私"
                        , this.dateTimePicker1.Value.Date.ToString("yyyyMMdd")
                        , nCount);

                        string strIsFacDirect = (bool)ugr[i].Cells["是否直接开票"].Value ? "G" : "B";
                        string strRet = strBianHao.Insert(7, strIsFacDirect);

                        modelFeeHKCWTruePayTabOld.ToPrivateBianHao = strRet;


                        CurrentUGR.Cells["对私费用编号"].Value = strRet;
                        nCount++;

                        modelFeeHKCWTruePayTabOld.bitFiledReserv2 = false;//编号是否手动生成

                        CurrentUGR.Cells["实付日期"].Value = this.dateTimePicker1.Value.Date;
                        CurrentUGR.Cells["编号是否手动生成"].Value = false;

                        m_bllFeeHKCWTruePayTab.TransUpdate(modelFeeHKCWTruePayTabOld
                            , m_SQLStringList, m_arrayList, i);

                       // CurrentUGR.Cells["实付日期"].Value = this.dateTimePicker1.Value.Date;
                    }
                }

                m_bllSJPackingTab.ExecuteSqlTran(m_SQLStringList, m_arrayList);
                Frm_Main.Log2DB(this.Text, "批量修改实付日期", this.dateTimePicker1.Value.Date.ToString());
                MessageBox.Show("批量修改实付日期完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

        }

        private void buttonExportExcel_Click(object sender, EventArgs e)
        {
            DataTable dt = (DataTable)ultraGrid1.DataSource;

            if (dt != null)
            {
                if (dt.Rows.Count > 0)
                {
                    SaveFileDialog sfd = new SaveFileDialog();
                    sfd.Filter = "Excel文件(*.xls)|*.xls";
                    string outFile = "";

                    if (sfd.ShowDialog() == DialogResult.OK)
                    {
                        outFile = sfd.FileName;
                    }
                    else
                    {
                        return;
                    }

                    ultraGridExcelExporter1.Export(ultraGrid1, outFile);
                }
            }
        }

        private void buttonSetEmpty_Click(object sender, EventArgs e)
        {
            m_SQLStringList.Clear();
            m_arrayList.Clear();

            try
            {
                bool bCanModify = true;

                Infragistics.Win.UltraWinGrid.UltraGridRow[] ugr = ultraGrid1.Rows.GetFilteredInNonGroupByRows();

                DialogResult dr = MessageBox.Show("确实要批量置空以下" + ugr.Length.ToString() + "条记录的实付日期么", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                if (dr == DialogResult.Cancel)
                    return;

                List<string> lstDT = new List<string>();
                for (int i = 0; i < ugr.Length; i++)
                {
                    string strTemp = ugr[i].Cells["对公费用编号"].Value.ToString() + ugr[i].Cells["对私费用编号"].Value.ToString();

                    if (strTemp != "" && lstDT.Count == 0)
                        lstDT.Add(strTemp);
                    else if (lstDT.Count > 0 && !lstDT.Contains(strTemp))
                    {
                        bCanModify = false;
                        break;
                    }

                }

                if (!bCanModify)
                {
                    MessageBox.Show("费用编号不相同，不能批量置空实付日期!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                ugr = ultraGrid1.Rows.GetFilteredInNonGroupByRows();
                for (int i = 0; i < ugr.Length; i++)
                {
                    UltraGridRow CurrentUGR = ultraGrid1.Rows[ugr[i].Index];
                    int nID = Convert.ToInt32(ugr[i].Cells[0].Value.ToString(), 10);
                    DGBY.Model.FeeHKCWTruePayTab modelFeeHKCWTruePayTabOld
                                        = m_bllFeeHKCWTruePayTab.GetModel(nID);
                    modelFeeHKCWTruePayTabOld.TruePayDate = null;
                    modelFeeHKCWTruePayTabOld.ToPrivateBianHao = "";
                    modelFeeHKCWTruePayTabOld.ToPubBianHao = "";

                    m_bllFeeHKCWTruePayTab.TransUpdate(modelFeeHKCWTruePayTabOld
                        , m_SQLStringList, m_arrayList, i);
                    CurrentUGR.Cells["对私费用编号"].Value = "";
                    CurrentUGR.Cells["对公费用编号"].Value = "";
                    CurrentUGR.Cells["实付日期"].Value = DBNull.Value;
                }

                m_bllSJPackingTab.ExecuteSqlTran(m_SQLStringList, m_arrayList);
                Frm_Main.Log2DB(this.Text, "批量置空实付日期", "");
                MessageBox.Show("批量置空实付日期完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
        }

        private void ultraGrid1_AfterCellUpdate(object sender, CellEventArgs e)
        {

            if (e.Cell.Column.Key == "实付金额")
            {
                int nIndex = e.Cell.Row.Index;
                if (nIndex < 0)
                    return;
                UltraGridRow CurrentUGR = ultraGrid1.Rows[nIndex];
                Decimal dJinE = (Decimal)e.Cell.Value;
                if (dJinE > 0)
                {
                    CurrentUGR.Cells["实付手续费"].Value = 50;
                    CurrentUGR.Cells["应收快递费"].Value = 30;

                }
                else
                {
                    CurrentUGR.Cells["实付手续费"].Value = 0;
                    CurrentUGR.Cells["应收快递费"].Value = 0;
                    CurrentUGR.Cells["实付汇率"].Value = 0;
                    CurrentUGR.Cells["应收汇率"].Value = 0;
                }
            }
        }

        private void 增加无合同号记录ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!m_bInsertFlag)
            {
                m_InsertType = InsertType.WithoutContractNo;
                DataSet ds;
                UltraGridRow CurrentUGR = ultraGrid1.Rows[m_nDelIndex];
                string strFac = CurrentUGR.Cells["工厂简称"].Value.ToString();
                if (ClassInputValid.IsNum(strFac))
                {
                    m_nFacID = Convert.ToInt32(CurrentUGR.Cells["工厂简称"].Value.ToString(), 10);
                }
                else
                {
                    ds = m_bllFactoryDataTab.GetList("FactoryNameJX = '" + strFac + "'");
                    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        m_nFacID = Convert.ToInt32(ds.Tables[0].Rows[0]["FactoryDataTabID"].ToString(), 10);
                    }
                }
                UltraGridRow row = this.ultraGrid1.DisplayLayout.Bands[0].AddNew();
                //  row.Cells[2] = DateTime.Parse("1900-01-01");
            }
        }

        private void buttonModYearMon_Click(object sender, EventArgs e)
        {

        }

        private void 清空该条记录ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DialogResult dr = MessageBox.Show("确实要清空该记录么!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
            if (dr == DialogResult.Cancel)
            {
                return;
            }
            int nIndex = m_nDelIndex;
            if (m_nDelIndex >= 0)
            {
                UltraGridRow CurrentUGR;
                CurrentUGR = ultraGrid1.Rows[nIndex];
                bool bRet = CheckModify(CurrentUGR);
                if (!bRet)
                {
                    MessageBox.Show("费用已锁定，不能修改或删除记录！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                bRet = IsFeeTruePayLocked(CurrentUGR);
                if (bRet)
                {
                    MessageBox.Show("实付费用已锁定，不能修改或删除记录！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                ResetUltraGridRow(nIndex);
               
                int nFeeSJTruePayTabID = Convert.ToInt32(CurrentUGR.Cells[0].Value.ToString(), 10);
                ResetRecord(nFeeSJTruePayTabID);
                m_bClearing = true;
            }
            else
            {
                MessageBox.Show("请选中要清空的记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            m_SQLStringList.Clear();
            m_arrayList.Clear();

            try
            {
                Infragistics.Win.UltraWinGrid.UltraGridRow[] ugr = ultraGrid1.Rows.GetFilteredInNonGroupByRows();

                DialogResult dr = MessageBox.Show("确实要批量置空以下" + ugr.Length.ToString() + "条记录的应收费用计提年月么", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                if (dr == DialogResult.Cancel)
                    return;


                for (int i = 0; i < ugr.Length; i++)
                {

                    int nID = Convert.ToInt32(ugr[i].Cells[0].Value.ToString(), 10);
                    DGBY.Model.FeeHKCWTruePayTab modelFeeHKCWTruePayTabOld
                                        = m_bllFeeHKCWTruePayTab.GetModel(nID);
                    modelFeeHKCWTruePayTabOld.ShouldPayMonth = 0;
                    UltraGridRow CurrentUGR = ultraGrid1.Rows[ugr[i].Index];

                    m_bllFeeHKCWTruePayTab.TransUpdate(modelFeeHKCWTruePayTabOld
                        , m_SQLStringList, m_arrayList, i);

                    CurrentUGR.Cells["应收费用计提年月"].Value = "0";
                }

                m_bllSJPackingTab.ExecuteSqlTran(m_SQLStringList, m_arrayList);
                Frm_Main.Log2DB(this.Text, "批量置空计提年月", "");
                MessageBox.Show("批量修改应收费用计提年月完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
        }
        private bool IsLiuShuiNo(string strInput)
        {
            return Regex.IsMatch(strInput, @"^[0-9]{3}$");
        }
        private bool IsLiuShuiNo(ErrorProvider errorProvider1, TextBox TextBox)
        {
            if (TextBox.Text == "")
            {
                errorProvider1.SetError(TextBox, "内容不能为空！");
                return false;
            }
            else if (!IsLiuShuiNo(TextBox.Text))
            {
                errorProvider1.SetError(TextBox, "必须001-999之间的流水号");
                return false;
            }
            else
            {
                errorProvider1.SetError(TextBox, "");
                return true;
            }
        }
        private void buttonBatchModFeeNo_Click(object sender, EventArgs e)
        {
            m_SQLStringList.Clear();
            m_arrayList.Clear();

            try
            {
                if (!IsLiuShuiNo(this.errorProvider1, this.textBoxLiuShuiNo))
                    return;
                Infragistics.Win.UltraWinGrid.UltraGridRow[] ugr = ultraGrid1.Rows.GetFilteredInNonGroupByRows();

                if (ugr.Length > 1)
                {
                    MessageBox.Show("一次只能修改一条记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                //DialogResult dr = MessageBox.Show("确实要批量修改以下" + ugr.Length.ToString() + "条记录的费用编号么", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                //if (dr == DialogResult.Cancel)
                //    return;

                for (int i = 0; i < ugr.Length; i++)
                {

                    int nID = Convert.ToInt32(ugr[i].Cells[0].Value.ToString(), 10);
                    DGBY.Model.FeeHKCWTruePayTab modelFeeHKCWTruePayTabOld
                                        = m_bllFeeHKCWTruePayTab.GetModel(nID);

                    DateTime? dtTruePayOld = modelFeeHKCWTruePayTabOld.TruePayDate;
                    if (dtTruePayOld != null)
                    {
                        MessageBox.Show("原记录实付日期不为空，不能修改，若要修改，请先置空实付日期!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }

                    modelFeeHKCWTruePayTabOld.TruePayDate = this.dateTimePicker1.Value.Date;

                    UltraGridRow CurrentUGR = ultraGrid1.Rows[ugr[i].Index];

             
                        if ((Decimal)CurrentUGR.Cells["实付金额"].Value > 0)
                        {
                            string strBianHao = MakeHKCWBianHaoWithoutLiuShuiNo(ugr[0].Cells["部门"].Value.ToString()
                                , ugr[i].Cells["经营单位"].Value.ToString()
                  , "私"
                   , this.dateTimePicker1.Value.Date.ToString("yyyyMMdd")
                   );

                            string strIsFacDirect = (bool)ugr[i].Cells["是否直接开票"].Value ? "G" : "B";
                            string strRet = strBianHao.Insert(7, strIsFacDirect) + this.textBoxLiuShuiNo.Text;

                            modelFeeHKCWTruePayTabOld.ToPrivateBianHao = strRet;
                            CurrentUGR.Cells["对私费用编号"].Value = strRet;
                        }

                        
                        modelFeeHKCWTruePayTabOld.bitFiledReserv2 = true;//编号是否手动生成
                        m_bllFeeHKCWTruePayTab.TransUpdate(modelFeeHKCWTruePayTabOld
                            , m_SQLStringList, m_arrayList, i);

                        CurrentUGR.Cells["实付日期"].Value = this.dateTimePicker1.Value.Date;
                        CurrentUGR.Cells["编号是否手动生成"].Value = true;
                    


                }

                m_bllSJPackingTab.ExecuteSqlTran(m_SQLStringList, m_arrayList);
                Frm_Main.Log2DB(this.Text, "批量修改实付日期", this.dateTimePicker1.Value.Date.ToString());
                MessageBox.Show("批量修改实付日期完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
        }

        private void buttonModRecvPerson_Click(object sender, EventArgs e)
        {
            m_SQLStringList.Clear();
            m_arrayList.Clear();

            try
            {

                Infragistics.Win.UltraWinGrid.UltraGridRow[] ugr = ultraGrid1.Rows.GetFilteredInNonGroupByRows();

                DialogResult dr = MessageBox.Show("确实要批量修改以下" + ugr.Length.ToString() + "条记录的收款人么", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                if (dr == DialogResult.Cancel)
                    return;

                for (int i = 0; i < ugr.Length; i++)
                {

                    int nID = Convert.ToInt32(ugr[i].Cells[0].Value.ToString(), 10);
                    DGBY.Model.FeeHKCWTruePayTab modelFeeHKCWTruePayTabOld
                                        = m_bllFeeHKCWTruePayTab.GetModel(nID);





                    UltraGridRow CurrentUGR = ultraGrid1.Rows[ugr[i].Index];


                    CurrentUGR.Cells["收款人"].Value = this.textBoxRecvPerson.Text;

                    modelFeeHKCWTruePayTabOld.RecvMonyePerson = this.textBoxRecvPerson.Text;//编号是否手动生成
                    m_bllFeeHKCWTruePayTab.TransUpdate(modelFeeHKCWTruePayTabOld
                        , m_SQLStringList, m_arrayList, i);


                    Frm_Main.Log2DB(this.Text, "批量修改收款人", this.textBoxRecvPerson.Text);

                }

                m_bllSJPackingTab.ExecuteSqlTran(m_SQLStringList, m_arrayList);
                MessageBox.Show("批量修改收款人完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
        }

    }
}
